﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    myColor=QColor(Qt::red);//默认红色
    lineSize=1;
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    //QColor selectCor=QColorDialog::getColor(Qt::red,nullptr,"选择颜色",QColorDialog::ShowAlphaChannel);
    QColorDialog colorDia;
    colorDia.setOption(QColorDialog::ShowAlphaChannel, true);//对话框选项
    if(colorDia.exec()==QDialog::Accepted)//弹出颜色对话框
    {
        myColor=colorDia.currentColor();//获得你选择的颜色
        qDebug()<<"你选的颜色是:"<<myColor;
        repaint();//更新
    }
    else
    {
        qDebug()<<"取消颜色选择";
    }
}

void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPen pen=painter.pen();//获得画家的笔
    pen.setColor(myColor);//设置笔颜色，只修改颜色
    pen.setWidth(lineSize);
    painter.setPen(pen);//还给画家
    painter.drawEllipse(100,0,100,100);
}

void MainWindow::on_horizontalSlider_valueChanged(int value)
{
    lineSize=value;
    ui->lcdNumber->setDecMode();
    ui->lcdNumber->display(value);
    repaint();
}

void MainWindow::on_comboBox_currentTextChanged(const QString &arg1)
{
    qDebug()<<arg1;
}
